package com.umer.pinban.adapter.customer;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.common.ui.recycleview.adapter.RecyclerviewBasicAdapter;
import com.common.ui.recycleview.base.ViewHolder;
import com.common.ui.recycleview.listener.OptListener;
import com.umer.pinban.R;
import com.umer.pinban.bean.customer.XiaoFeiRecordItemBean;
import java.util.List;

public class CustomerXiaoFeiRecordItemAdapter extends RecyclerviewBasicAdapter<XiaoFeiRecordItemBean> {

    private OptListener optListener;
    private int index;
    private int orderType;//订单类型
    private Context context;

    public CustomerXiaoFeiRecordItemAdapter(Context context, List<XiaoFeiRecordItemBean> datas,
                                            int layoutId, OptListener optListener, int position,int orderType) {
        super(context, datas, layoutId);
        this.index = position;
        this.optListener = optListener;
        this.orderType = orderType;
        this.context = context;
    }

    @Override
    public void convert(ViewHolder holder, XiaoFeiRecordItemBean xiaoFeiRecordItem, int position) {
        LinearLayout linear_lay3 =  holder.getView(R.id.linear_lay3);
        //1：购买；
        //2：消耗；
        //3：退款；
        //4：余额购买
        TextView tv_type = holder.getView(R.id.tv_type);
        TextView tv_pro_name = holder.getView(R.id.tv_pro_name);
        TextView tv_desc_one = holder.getView(R.id.tv_desc_one);
        TextView tv_desc_two = holder.getView(R.id.tv_desc_two);
        TextView tv_staff_name = holder.getView(R.id.tv_staff_name);

        if(orderType == 1){
            tv_type.setText(context.getString(R.string.goumai));
            tv_type.setTextColor(context.getColor(R.color.hint2));
        }else if(orderType == 2){
            tv_type.setText(context.getString(R.string.xiaohao));
            tv_type.setTextColor(context.getColor(R.color.colorPrimary));
        }else if(orderType == 3){
            tv_type.setText(context.getString(R.string.tuikuan));
            tv_type.setTextColor(context.getColor(R.color.hint2));
        }else if(orderType == 4){
            tv_type.setText("余额购买:");
            tv_type.setTextColor(context.getColor(R.color.hint2));
        }

        if(xiaoFeiRecordItem.getName()!=null && !xiaoFeiRecordItem.getName().equals("null")){
            tv_pro_name.setText(xiaoFeiRecordItem.getName());
        }else {
            tv_pro_name.setText("");
        }

        if(orderType == 1){
            tv_desc_two.setVisibility(View.GONE);
            String desc = "¥"+ " " + xiaoFeiRecordItem.getPrice()+ " x "+ xiaoFeiRecordItem.getBuyNum();
            tv_desc_one.setText(desc);
        }else if(orderType == 2){
            int useType = xiaoFeiRecordItem.getUseType();
            //1 不限制次数
            if(useType == 1){
                if(xiaoFeiRecordItem.getUseNum()!=0){
                    tv_desc_one.setVisibility(View.VISIBLE);
                    tv_desc_one.setText(xiaoFeiRecordItem.getUseNum()+"次");
                }else {
                    tv_desc_one.setVisibility(View.GONE);
                }
                tv_desc_two.setVisibility(View.VISIBLE);
                String txt = xiaoFeiRecordItem.getUseTime();
                int month = Integer.valueOf(txt);
                String desc = "";
                if(month<=1){
                    desc = "到期日期: "+ xiaoFeiRecordItem.getUseTimeDate();
                }else {
                    desc = "剩余: "+ month+"个月";
                }
                tv_desc_two.setText(desc);
            }
            //限制次数
            else if(useType == 0){
                tv_desc_one.setVisibility(View.VISIBLE);
                tv_desc_two.setVisibility(View.VISIBLE);
                String descOne = xiaoFeiRecordItem.getUseNum()+ "次" + " "+  "(剩余"+ xiaoFeiRecordItem.getSurplusNum()+"次可用)";
                tv_desc_one.setText(descOne);
                String txt = xiaoFeiRecordItem.getUseTime();
                if(txt != null && !txt.equals("null")&& !txt.equals("")&& !txt.equals(" ")){
                    tv_desc_two.setVisibility(View.VISIBLE);
                    int month = Integer.valueOf(txt);
                    String descTwo = "";
                    if(month<=1){
                        descTwo = "到期日期: "+ xiaoFeiRecordItem.getUseTimeDate();
                    }else {
                        descTwo = "剩余: "+ month+"个月";
                    }
                    tv_desc_two.setText(descTwo);
                }else {
                    tv_desc_two.setVisibility(View.GONE);
                }
            }
        }else if(orderType == 3){
            tv_desc_two.setVisibility(View.GONE);
            String desc = "¥"+ " " + xiaoFeiRecordItem.getPrice()+ " "+ xiaoFeiRecordItem.getBuyNum();
            tv_desc_one.setText(desc);
        }else if(orderType == 4){
            tv_desc_two.setVisibility(View.GONE);
            String desc = "¥"+ " " + xiaoFeiRecordItem.getPrice()+ " "+ xiaoFeiRecordItem.getBuyNum();
            tv_desc_one.setText(desc);
        }
        tv_staff_name.setText(xiaoFeiRecordItem.getPersonnelName());
        linear_lay3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                optListener.onOptClick(v,index);
            }
        });
    }

}
